package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.rare;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

public class StealthSkill extends BaseSkill {

    public StealthSkill(int level) {
        super(level);
    }

    public StealthSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public StealthSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMaxlevel(10);
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return String.format("坚守技能，获得(技能等级*0.1)击退抗性。");
    }

    @Override
    public SkillRarity getSkillRarity() {
        return SkillRarity.Rare;
    }

    @Override
    public boolean canUseAbility(MobEntity mobEntity) {
        return (getSkilltime() < mobEntity.world.getTime());
    }

    @Override
    public Integer getCooldown() {
        return (super.getCooldown() - getSkillLevel() * 15);
    }

    @Override
    public boolean onDamaged(LivingEntity attacker, MobEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        if (target.hasStatusEffect(StatusEffects.INVISIBILITY)) {
            setSkilltime(target.world.getTime() + getCooldown());
            target.removeStatusEffect(StatusEffects.INVISIBILITY);
        }
        return true;
    }

    @Override
    public boolean passiveApply(MobEntity mobEntity) {
        if (!mobEntity.hasStatusEffect(StatusEffects.INVISIBILITY) && canUseAbility(mobEntity)) {
            StatusEffectInstance statusEffectInstance = new StatusEffectInstance(StatusEffects.INVISIBILITY, 200);
            mobEntity.addStatusEffect(statusEffectInstance);
        }
        return true;
    }
}
